package com.wlyuan.open.application.translator;

import com.wlyuan.core.domain.MappingIds;
import com.wlyuan.open.domain.api.OpenApi;
import com.wlyuan.open.domain.api.OpenApiDoc;
import com.wlyuan.open.domain.api.utils.MappingOpenApi;
import com.wlyuan.open.domain.api.utils.MappingOpenApiDoc;
import com.wlyuan.open.vo.OpenApiDocDetailVO;
import com.wlyuan.open.vo.OpenApiDocVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author yuanzheng
 */
public class OpenApiDocTranslator {

    @Mapper(uses = {MappingIds.class, MappingOpenApiDoc.class, MappingOpenApi.class})
    public interface Translator {

        @Mappings({
                @Mapping(source = "name", target = "apiName"),
                @Mapping(source = "id", target = "apiId")
        })
        OpenApiDocVO translate(OpenApi source);

        List<OpenApiDocVO> translate(List<OpenApi> source);

        @Mappings({
                @Mapping(source = "apiName", target = "apiName")
        })
        OpenApiDocDetailVO translate(OpenApiDoc source, String apiName);
    }

    private static final Translator TRANSLATOR = Mappers.getMapper(Translator.class);

    public static OpenApiDocDetailVO translate(OpenApiDoc source, String apiName) {
        return TRANSLATOR.translate(source, apiName);
    }

    public static List<OpenApiDocVO> translate(List<OpenApi> source) {
        return TRANSLATOR.translate(source);
    }
}
